/*
 * @Author: Yeong Lee
 * @Date: 2021-02-15 00:54:22
 * @Last Modified by: Yeong Lee
 * @Last Modified time: 2021-02-18 03:31:16
 */
import { applyMiddleware, createStore } from 'redux';
import createSagaMiddleware from 'redux-saga';
import reducers from '../reducers';
import sagas from '../sagas';

// create the saga middleware
const sagaMiddleware = createSagaMiddleware({
  onError(error, errorInfo): void {
      console.warn('SAGA异常:', error.message, errorInfo.sagaStack);
  }
});

// 组合middleware
const middlewares = [sagaMiddleware];

export default (initialStore = {})=>{
  const store = createStore(
    reducers,
    initialStore,
    applyMiddleware(...middlewares),
  );
  store.sagaTask = sagaMiddleware.run(sagas);
  return store;
};
